package com.example.hanchen.yongkanggy.home.adapter;

import android.content.Context;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.List;

public class FragmentListAdapter extends FragmentStatePagerAdapter {
    private List<Fragment> fragments;
    public FragmentListAdapter(Context context, List<Fragment> fragmentList) {
        super(((FragmentActivity)context).getSupportFragmentManager());
        this.fragments = fragmentList;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }


    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }

    @Override
    public int getItemPosition(Object object) {
        if (fragments.contains(object)) {
            return fragments.indexOf(object);
        } else {
            return POSITION_NONE;
        }
    }

}